package org.odata4j.examples.consumer;

import org.odata4j.consumer.ODataConsumer;
import org.odata4j.consumer.ODataConsumers;
import org.odata4j.core.*;
import org.odata4j.edm.EdmDataServices;
import org.odata4j.examples.AbstractExample;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 *
 */
public class MediaWikiConsumer extends AbstractExample {

	public static void main(String[] args) {
		MediaWikiConsumer example = new MediaWikiConsumer();
		example.run(args);
	}

	private void run(String[] args) {

		ODataConsumer c = ODataConsumers.create("http://localhost:7968/ODataMediaWikiProducer.svc/");
		String pageTitle = "NewTestPage5";
		String pageContent = "some content555   moreee data more more more";
		report("Create a new Page");
		OEntity newPage = c.createEntity("Pages")
				.properties(OProperties.string("displaytitle", pageTitle))
				.properties(OProperties.string("PageContent", pageContent))
				.execute();
		report("Create a new Page done");

		EdmDataServices metadata = c.getMetadata();
		List<OProperty<?>> properties = new ArrayList<OProperty<?>>();
		properties.add(OProperties.string("displaytitle", "Aashish"));

		OEntity pageToEdit = OEntities.create(metadata.getEdmEntitySet("Pages"), OEntityKey.create("Aashish"), properties, new ArrayList<OLink>());
		c.updateEntity(pageToEdit)
				.properties(OProperties.string("displaytitle", "Aashish"))
				.properties(OProperties.string("PageContent", "This page has been edited."))
				.execute();
		report("Edit Page done");



	}
}
